﻿package com.wandian.view.components.ui
{
	import com.wandian.ApplicationFacade;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.AccountProxy;
	import com.wandian.model.vo.FaceVo;
	import com.wandian.model.vo.FriendVo;
	import com.wandian.model.vo.PlayerVo;
	import com.wandian.model.vo.PropVo;
	import com.wandian.model.vo.RoomVo;
	import com.wandian.util.CLZButton;
	import com.wandian.util.CLZLlistScrollPanel;
	import com.wandian.util.CLZLoadIcon;
	import com.wandian.util.CLZTabBar;
	import com.wandian.util.CLZZoom;
	import com.wandian.util.GlowFilterManage;
	import com.wandian.util.ToolTip;

	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;

	/**
	 * 玩家列表小图标
	 * name_txt 名称
	 * money_txt 金钱
	 * state_txt 状态
	 * icon_mc 头像略缩图
	 * @author long
	 * @QQ 108232706
	 * @version 1.0
	 */
	public class PlayerInfoMc extends EventDispatcher
	{
		private var _mcInfo:MovieClip;
		private var _type:String;
		private const UP:int=1;
		private const OVER:int=2;
		private const DOWN:int=3;
		private var friendVo:FriendVo;
		private var _global:GameData;
		private var _filter:GlowFilterManage;

		public function PlayerInfoMc(mcInfo:MovieClip, myfriendVo:FriendVo, type:String, roomid:int=0)
		{
			var roomVo:RoomVo=null;
			this._global=GameData.getInstance();
			this._filter=GlowFilterManage.getInstance();
			this.friendVo=myfriendVo;
			this._type=type;
			this._mcInfo=mcInfo;
			this._mcInfo.cacheAsBitmap=true;
			this._mcInfo.gotoAndStop(this.UP);
			this._mcInfo.buttonMode=true;
			this._mcInfo.doubleClickEnabled=true;
			this._mcInfo.addEventListener(MouseEvent.ROLL_OUT, this.outHandler);
			this._mcInfo.addEventListener(MouseEvent.ROLL_OVER, this.overHandler);
			this._mcInfo.addEventListener(MouseEvent.DOUBLE_CLICK, this.onDoubleHandler);
			this._mcInfo.addEventListener(MouseEvent.CLICK, this.onHandler);
			this._mcInfo["name_txt"].text=myfriendVo.name;
			this._mcInfo["money_txt"].textColor=16773120;
			if (myfriendVo.headImage != null)
			{
				CLZLoadIcon.addBytesIcon(this._mcInfo["icon_mc"], myfriendVo.headImage, 50, 50, 0, 0, "InitPicGirlIcon", false, false);
			}
			else
			{
				if (myfriendVo.sex == 1)
				{
					CLZLoadIcon.addIcon(this._mcInfo["icon_mc"], myfriendVo.icon, 50, 50, 0, 0, "InitPicGirlIcon", false, false);
				}
				else
				{
					CLZLoadIcon.addIcon(this._mcInfo["icon_mc"], myfriendVo.icon, 50, 50, 0, 0, "InitPicBoyIcon", false, false);
				}
			}
			this._mcInfo["icon_mc"].buttonMode=true;
			this._mcInfo["icon_mc"].mouseChildren=false;
			this._mcInfo["icon_mc"].addEventListener(MouseEvent.CLICK, this.onInfoHandler);
			if (type == CLZNoticeName.FRIEND_LIST_RES)
			{
				this._mcInfo["money_txt"].text=this._global.counstK(myfriendVo.money) + " " + GameData.tip["GOLD"];
				if (myfriendVo.state)
				{
					this._mcInfo.alpha=1;
					if (GameData._objRoom)
					{
						this._mcInfo["state_txt"].htmlText="<font color=\'#00ff00\'>" + GameData.tip["ON_LINE_NAME"] + "</font>";
					}
					else
					{
						this._mcInfo["state_txt"].htmlText="<a href=\"event:" + myfriendVo.userid + "\"><u><font color=\'#ffff00\'>" + GameData.tip["TRACK"] + "</font></u></a>";
						this._mcInfo["state_txt"].addEventListener(TextEvent.LINK, this.linkTxtHandler);
					}
					this._mcInfo.filters=null;
				}
				else
				{
					this._mcInfo.filters=this._filter.getGrayscale();
					this._mcInfo.alpha=0.5;
					this._mcInfo["state_txt"].htmlText=GameData.tip["OFF_LINE_NAME"];
				}
			}
			else
			{
//				roomVo=GameData.getRoomInfoById(GameData.ALL, roomid);
//				if (roomVo != null)
//				{
//					if (!this._global.judgeMoneyType(roomVo.type))
//					{
//						this._mcInfo["money_txt"].text=this._global.counstK(myfriendVo.money) + " " + GameData.tip["MONEY"];
//					}
//					else
//					{
//						this._mcInfo["money_txt"].text=this._global.counstK(myfriendVo.money) + " " + GameData.tip["GOLD"];
//					}
//				}
				this._mcInfo["money_txt"].text=this._global.counstK(myfriendVo.money) + " " + GameData.tip["MONEY"];
				this._mcInfo.alpha=1;
				this._mcInfo["state_txt"].htmlText=myfriendVo.state == 0 ? ("<font color=\'#ffffff\'>" + GameData.tip["LOOK_ON"] + "</font>") : ("<font color=\'#00ff00\'>" + GameData.tip["PLAYING"] + "</font>");
			}
			return;
		}

		private function onInfoHandler(event:MouseEvent):void
		{
			var playerVo:PlayerVo=new PlayerVo();
			playerVo.userid=this.friendVo.userid;
			playerVo.name=this.friendVo.name;
			playerVo.sex=this.friendVo.sex;
			playerVo.headImage=this.friendVo.headImage;
			playerVo.level=this.friendVo.level;
			playerVo.money=this.friendVo.money;
//			playerVo.level=this.friendVo.level;
			playerVo.rank=this.friendVo.rank;
			playerVo.icon=this.friendVo.icon;
			ApplicationFacade.getInstance().sendNotification(CLZNoticeName.SHOW_ACCOUNT, playerVo);
			return;
		}

		private function linkTxtHandler(event:TextEvent):void
		{
			ApplicationFacade.getInstance().sendNotification(CLZNoticeName.TRACK_ROOM, uint(event.text));
			return;
		}

		private function onHandler(event:MouseEvent):void
		{
			this._mcInfo.gotoAndStop(this.DOWN);
			return;
		}

		private function onDoubleHandler(event:MouseEvent):void
		{
			return;
		}

		private function outHandler(event:MouseEvent=null):void
		{
			this._mcInfo.gotoAndStop(this.UP);
			return;
		}

		private function overHandler(event:MouseEvent):void
		{
			this._mcInfo.gotoAndStop(this.OVER);
			return;
		}

	}
}
